#include "startupeditor.h"
#include "../application.h"
#include "../document.h"

#include <QPaintEvent>
#include <QPainter>
#include <QLinearGradient>
#include <QTimer>


StartupEditor::View::View(QWidget* parent)
    : QWidget(parent)
    , m_fPos(0)
    , m_fDir(1)
{
    setBackgroundRole(QPalette::Dark);
    connect(&m_timer, SIGNAL(timeout()), this, SLOT(onTimer()));

}
void StartupEditor::View::paintEvent(QPaintEvent* pEvent)
{
    float w = rect().width(), h = rect().height();
    QRect ar = rect().adjusted(10, h/2.5, -10, -h/2.5);

    QLinearGradient gr(ar.left(), 0, ar.right(), ar.bottom());
    gr.setColorAt(0, Qt::darkBlue);
    gr.setColorAt(1, Qt::darkBlue);
    gr.setColorAt(m_fPos, Qt::blue);

    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setBrush(gr);
    painter.drawRoundedRect(ar, 30*rect().width()/600, 30*rect().width()/600);

    QFont f = font();
    f.setPixelSize(30*rect().width()/600);
    painter.setFont(f);
    painter.setPen(Qt::black);
    painter.drawText(rect(), Qt::AlignCenter, "Navigate menu bar to create new Project");
}

void StartupEditor::View::showEvent(QShowEvent *)
{
    m_timer.start(30);
}

void StartupEditor::View::hideEvent(QHideEvent *)
{
    m_timer.stop();
}

void StartupEditor::View::onTimer()
{
    m_fPos += 0.01f*m_fDir;
    if(m_fPos < 0.0f)
    {
        m_fDir = -m_fDir;
        m_fPos = 0.0f;
    }

    if(m_fPos > 1.0f)
    {
        m_fDir = -m_fDir;
        m_fPos = 1.0f;
    }

    update();
}

StartupEditor::StartupEditor(QObject *parent) :
    AbstractEditor(parent)
{

}

bool StartupEditor::init()
{
    m_view = new View();
   // m_tools = new QLabel("Test");

   // m_tools->setWindowFlags(Qt::WindowStaysOnTopHint);

    return true;
}
